package com.hspedu.Homework;
/*
 *@auther will
 *@version 1.0
 */

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class CollectionExercise {
    public static void main(String[] args) {
        List col = new ArrayList();
        col.add(new Dog("小花",2));
        col.add(new Dog("阿黄",3));
        col.add(new Dog("豆花",4));

        Iterator iterator = col.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println(next);
        }
        System.out.println("================");
        for (Object o : col) {
            System.out.println(o);
        }
    }
}

class Dog{
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
